package com.meihua.shellapp.activity.set;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.lzy.okgo.OkGo;
import com.meihua.shellapp.R;
import com.meihua.shellapp.activity.set.SetNewPayPwdActivity;
import com.meihua.shellapp.base.BaseActivity;
import com.meihua.shellapp.base.BaseBean;
import com.meihua.shellapp.base.MyApplication;
import com.meihua.shellapp.utils.MyStringCallBack;
import com.meihua.shellapp.utils.ToastUtils;
import com.meihua.shellapp.utils.URL;

import butterknife.Bind;

/**
 * 验证身份证号
 * 作者：lc on 2017/10/19.
 * 邮箱：lc0607live@163.com
 */

public class VerificatoinPayPwdActivity extends BaseActivity {


    @Bind(R.id.iv_top_left)
    ImageView iv_top_left;//返回
    @Bind(R.id.tv_title)
    TextView tv_title;//标题

    @Bind(R.id.tv_message)
    TextView tv_message;//提示信息
    @Bind(R.id.et_oldpwd)
    EditText et_oldpwd;//身份证号
    @Bind(R.id.bt_next)
    Button bt_next;//下一步

    @Override
    public int getLayoutId() {
        return R.layout.activity_verificatoin_paypwd;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        tv_title.setVisibility(View.VISIBLE);
        iv_top_left.setVisibility(View.VISIBLE);
        tv_title.setText("重置支付密码");
        iv_top_left.setOnClickListener(this);
        bt_next.setOnClickListener(this);
        tv_message.setText("请为您的帐号" + MyApplication.getInstance().bean.getPhone().substring(0, 3) + "****" + MyApplication.getInstance().bean.getPhone().substring(7, 11)
                + "设置一个新的支付密码");
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.bt_next://下一步
                if (et_oldpwd.getText().toString().length() < 6) {
                    ToastUtils.getInstance().showToast("旧密码必须为6位数字！");
                    return;
                }
                verificationPayPwd();
                break;
        }
    }

    /**
     * 验证支付密码
     */
    private void verificationPayPwd() {
        OkGo.<String>post(URL.getUrl().VERIFICATIONPAYPWD)
                .params("m_number", MyApplication.getInstance().getUserId())
                .params("pay_password", et_oldpwd.getText().toString())
                .execute(new MyStringCallBack<BaseBean>(bt_next) {
                    @Override
                    public void onSuccessData(BaseBean bean) {
                        super.onSuccessData(bean);
                        if (bean.getCode() == 1) {
                            Intent in = new Intent(mContext, SetNewPayPwdActivity.class);
                            startActivity(in);
                            finish();
                        } else {
                            ToastUtils.getInstance().showToast(bean.getMsg());
                        }
                    }
                });
    }

}
